<script setup>

import { reactive, toRefs, onMounted } from 'vue'
import api from '@/api'
import { ElMessage } from 'element-plus'
import { useUserStore } from '@/store/modules/user'

const user = useUserStore()
user.loadList()
    
const data = reactive({
    drawer: false,
    formSearch: {
        id: '',
        name: '',
        status: ''
    },
    tableData: [],
    formData: {
        deptId: '',
        clientId: '1',
        menuIds: ''

    }
})

const onSubmit = () => {
    return new Promise((resolve, reject) => {
        api.post('api/mgr/deptList', {
            name: data.formSearch.name
        }).then(res => {

            data.tableData = res.d.records.map(i => {
                return {
                    id: i.id,
                    name: i.name,
                    status: i.status ? '正常' : '失效'
                }
            })

            console.log(data.tableData)
            
            resolve()
        })
    })
        
}

const submit = () => {
    api.post('api/mgr/deptMenuEdit', data.formData)
        .then(res => {
            if (res.c === 0) {
                ElMessage({
                    message: '权限编辑成功',
                    type: ''
                })
            } else {
                ElMessage({
                    message: res.m,
                    type: 'error'
                })
            }
        })
        
}

onSubmit()

const { formSearch, tableData, formData, drawer } = toRefs(data)

</script>

<template>
    <div class="content">
        <page-main>
            <div id="form">
                <div>
                    <el-form :inline="true" :model="formSearch" class="demo-form-inline" size="mini">
                        <el-form-item label="部门">
                            <el-input  v-model="formSearch.name" style="width: 80px" placeholder="输入部门" />
                        </el-form-item>
                        
                        <el-form-item>
                            <el-button type="primary" @click="onSubmit">查询</el-button>
                        </el-form-item>
                    </el-form>
                </div>

                <el-table
                    :data="tableData" :cell-style="rowClass"
                    style="width: 330px;height:350px;font-size: 10px;"
                >
                    <el-table-column
                        fixed
                        prop="id"
                        label="ID"
                        width="80px"
                    />
                    <el-table-column
                        fixed
                        prop="name"
                        label="部门"
                        width="120px"
                    />
                    <el-table-column
                        fixed
                        prop="status"
                        label="状态"
                        width="120px"
                    />
                </el-table>

                <!-- <el-button type="primary" style="margin-top: 20px;" @click="drawer = true">权限操作</el-button> -->

                <!-- <el-drawer
                    v-model="drawer"   
                    title="操作"			
                    direction="rtl"
                    custom-class="demo-drawer"
                    size="30%"
                > -->
                <el-card style="margin-top: 40px;">
                    <el-form>
                        <el-form-item label="部门ID">
                            <el-input  v-model="formData.deptId" />
                        </el-form-item>
                        <el-form-item label="客户端">
                            <el-select v-model="formData.clientId" placeholder="请选择客户端">
                                <el-option label="PC端" value="1" />
                                <el-option label="手机端" value="2" />
                            </el-select>
                        </el-form-item>
                        <el-form-item label="菜单ID">
                            <el-input  v-model="formData.menuIds" type="textarea" placeholder="授权的全量菜单id,多个以逗号分隔" />
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" :loading="loading" @click="submit">提&nbsp;&nbsp;&nbsp;&nbsp;交</el-button>
                        </el-form-item>
                    </el-form>
                <!-- </el-drawer> -->
                </el-card>
            </div>
        </page-main>
    </div>
</template>

<style>
   
</style>